﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace SimpleCalc
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        Calculator calc;

        public MainWindow()
        {
            InitializeComponent();
            calc = new Calculator();
            Value.IsEnabled = false;
            
        }

        private void Button_0_Click(object sender, RoutedEventArgs e)
        {
            calc.AddDigit(0);
            update();
        }

        private void Button_1_Click(object sender, RoutedEventArgs e)
        {
            calc.AddDigit(1);
            update();
        }

        private void Button_2_Click(object sender, RoutedEventArgs e)
        {
            calc.AddDigit(2);
            update();
        }

        private void Button_3_Click(object sender, RoutedEventArgs e)
        {
            calc.AddDigit(3);
            update();
        }

        private void Button_4_Click(object sender, RoutedEventArgs e)
        {
            calc.AddDigit(4);
            update();
        }
        
        private void Button_5_Click(object sender, RoutedEventArgs e)
        {
            calc.AddDigit(5);
            update();
        }

        private void Button_6_Click(object sender, RoutedEventArgs e)
        {
            calc.AddDigit(6);
            update();
        }
        
        private void Button_7_Click(object sender, RoutedEventArgs e)
        {
            calc.AddDigit(7);
            update();
        }

        private void Button_8_Click(object sender, RoutedEventArgs e)
        {
            calc.AddDigit(8);
            update();
        }

        private void Button_9_Click(object sender, RoutedEventArgs e)
        {
            calc.AddDigit(9);
            update();
        }

        private void Add_Click(object sender, RoutedEventArgs e)
        {
            calc.AddOperator(new Addition());
            update();
        }

        private void Subtract_Click(object sender, RoutedEventArgs e)
        {
            calc.AddOperator(new Subtraction());
            update();
        }

        private void Multiply_Click(object sender, RoutedEventArgs e)
        {
            calc.AddOperator(new Multiplication());
            update();
        }

        private void Divide_Click(object sender, RoutedEventArgs e)
        {
            calc.AddOperator(new Division());
            update();
        }

        private void Backspace_Click(object sender, RoutedEventArgs e)
        {
            calc.Backspace();
            update();
        }

        private void Equals_Click(object sender, RoutedEventArgs e)
        {
            calc.Compute();
            update();
        }

        private void update()
        {
            EquationEntered.Content = calc.CurrentEquation;
            Value.Text = (calc.LastNumeric.Length > 0) ? calc.LastNumeric : "0";
        }

        private void Clear_Click(object sender, RoutedEventArgs e)
        {
            calc.Clear();
            update();
        }
    }
}
